package jmine.tec.script.persistent.repository;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

/**
 * Implementação mock de BeanFactory para passar objetos abitrários à fábrica de contextos de scripts.
 * 
 * @author lundberg
 */
public class MockBeanFactory implements BeanFactory {

    private Map<String, Object> beans = new HashMap<String, Object>();

    public void addBean(String name, Object bean) {
        this.beans.put(name, bean);
    }

    public void clean() {
        this.beans.clear();
    }

    /**
     * {@inheritDoc}
     */
    public boolean containsBean(String name) {
        return this.beans.containsKey(name);
    }

    /**
     * {@inheritDoc}
     */
    public String[] getAliases(String name) {
        return new String[0];
    }

    /**
     * {@inheritDoc}
     */
    public Object getBean(String name) throws BeansException {
        return this.beans.get(name);
    }

    /**
     * {@inheritDoc}
     */
    public Object getBean(String name, Class requiredType) throws BeansException {
        return this.beans.get(name);
    }

    /**
     * {@inheritDoc}
     */
    public Object getBean(String name, Object[] args) throws BeansException {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    public Class getType(String name) throws NoSuchBeanDefinitionException {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isPrototype(String name) throws NoSuchBeanDefinitionException {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
        throw new UnsupportedOperationException();
    }
}
